package com.smartpower.wattmeter;

import android.app.Application;
import android.os.Handler;

import androidx.core.content.ContextCompat;

import com.android.basiclib.base.BaseLibCore;
import com.android.basiclib.receiver.ConnectivityReceiver;
import com.android.basiclib.uitls.ThreadPoolUtils;
import com.android.basiclib.view.titlebar.EasyTitleBar;
import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.google.gson.Gson;
import com.tencent.bugly.crashreport.CrashReport;


public class MyApplication extends Application {

    private static Gson mGson = new Gson();

    @Override
    public void onCreate() {
        super.onCreate();

        //全局的 CommUtil的初始化
        BaseLibCore.init(this, new Handler(), android.os.Process.myTid());

        //网络监听
        ConnectivityReceiver.registerReceiver(this);

        //获取到线程池对象
        ThreadPoolUtils.getCachedThreadPool().execute(() -> {
            //线程中初始化EasyTitle
            EasyTitleBar.init()
                    .backIconRes(R.mipmap.back_white)
                    .backgroud(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
                    .titleSize(18)
                    .showLine(true)
                    .lineHeight(1)
                    .menuImgSize(22)
                    .menuTextSize(15)
                    .menuTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white))
                    .lineColor(ContextCompat.getColor(getApplicationContext(), R.color.divider_color))
                    .showLine(false)
                    .titleColor(ContextCompat.getColor(getApplicationContext(), R.color.white))
                    .titleBarHeight(48);
        });

        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        SDKInitializer.initialize(this);
        //包括BD09LL和GCJ02两种坐标，默认是BD09LL坐标。
        SDKInitializer.setCoordType(CoordType.BD09LL);

        //bugly
        CrashReport.initCrashReport(getApplicationContext(), "6ac14232d9", false);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        ConnectivityReceiver.unregisterReceiver(this);
    }


    public static Gson getGson() {
        return mGson;
    }
}
